//package org.poem.datasource;
//
//import com.zaxxer.hikari.HikariDataSource;
//import lombok.Data;
//import org.poem.ContextDatabase;
//import org.poem.DataSourceDriverHelper;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.stereotype.Component;
//
//import javax.sql.DataSource;
//
///**
// * @author sangfor
// */
//@Component
//@Data
//@ConditionalOnExpression("environment['spring.postgres.datasource.url'] != ''  && environment['spring.postgres.datasource.url'] != null  ")
//@ConfigurationProperties(prefix = "spring.postgres.datasource")
//public class PostgresDatasourceJdbcUtils {
//
//    private static final Logger logger = LoggerFactory.getLogger(PostgresDatasourceJdbcUtils.class);
//
//    private String driverClassName;
//    private String url;
//    private String username;
//    private String password;
//
//    @Bean(name = "postgres")
//    public DataSource hiveHikariDataSource() {
//        logger.info("\nInit postgresJdbcTemplate  DataBase [" + DataSourceDriverHelper.getDatasourceType(url) + "] : " +
//                "\n\t\t [driverClassName]:" + DataSourceDriverHelper.getJdbc(url) +
//                "\n\t\t [url]:" + url +
//                "\n\t\t [user]:" + username +
//                "\n\t\t [password]:" + password
//        );
//        HikariDataSource dataSource = new HikariDataSource();
//        dataSource.setDriverClassName(DataSourceDriverHelper.getJdbc(url));
//        dataSource.setJdbcUrl(url);
//        dataSource.setUsername(username);
//        dataSource.setPassword(password);
//        dataSource.setMaximumPoolSize(30);
//        dataSource.addDataSourceProperty("cachePrepStmts", "true");
//        dataSource.addDataSourceProperty("prepStmtCacheSize", "500");
//        dataSource.addDataSourceProperty("prepStmtCacheSqlLimit", "5000");
//        dataSource.setIdleTimeout(300000);
//        dataSource.setValidationTimeout(60000);
//        dataSource.setMaxLifetime(600000);
//        return dataSource;
//    }
//
//    @Bean(name = "postgresJdbcTemplate")
//    public JdbcTemplate hiveJdbcExcuetor(@Qualifier("postgres") DataSource hiveHikariDataSource) {
//        ContextDatabase.setAppSchema(DataSourceDriverHelper.getDatasourceType(url));
//        ContextDatabase.setAppCatalog(DataSourceDriverHelper.getCatalog(url));
//        return new JdbcTemplate(hiveHikariDataSource);
//    }
//}
